
if exists (select * from dbo.sysobjects where name='sp_TimKiemDeAnNhanVien')
begin
		drop proc sp_TimKiemDeAnNhanVien
end
go

create proc sp_TimKiemDeAnNhanVien
	@MANV	nvarchar(10)
as
begin
if exists (select * from PHANCONG where MA_NVIEN=@MANV)
	begin
		if not exists(select * from dbo.sysobjects where name='KETQUATIMKIEM')
		begin
			create table KETQUATIMKIEM
			(
				MaNV	nvarchar(10),
				TenNV	nvarchar(10),
				MaDA	int,
				TenDA	nvarchar(30),
				ThoiGian	numeric	
			)
			
		end
		else
			begin
				delete from KETQUATIMKIEM where MANV=@MANV
				insert into KETQUATIMKIEM
			select A.MaNV,A.TenNV,C.MaDA,C.TenDA,B.ThoiGian
			from
				NHANVIEN as A
				inner join PHANCONG as B on A.MANV=B.MA_NVIEN
				inner join	DEAN as C on B.SODA=C.MADA
			where	MANV=@MANV	
			end
				select * from KETQUATIMKIEM	where @MANV=MANV

	end

else
	begin
			print 'nhan vien nay dang ngoi choi'

	end
end